package com.hxd.tabactivityfragment.util

import com.hxd.tabactivityfragment.R
import com.hxd.tabactivityfragment.base.BaseFragment
import com.hxd.tabactivityfragment.ui.fragment.HomeFragment
import com.hxd.tabactivityfragment.ui.fragment.FindFragment
import com.hxd.tabactivityfragment.ui.fragment.MineFragment

/*
 *  项目名：    HeimaPlayer
 *  包名：      com.itheima.plaer.util
 *  文件名:     FragmentUtil
 *  创建者:     HXD
 *  创建时间:   2019/2/27 21:37
 *  描述:       管理Fragment的Util类
 */

class FragmentUtil private constructor() {
    //私有化构造方法
    private val homeFragment by lazy { HomeFragment() }
    private val messageFragment by lazy { FindFragment() }
    private val mineFragment by lazy { MineFragment() }

    companion object {
        val fragmentUtil by lazy { FragmentUtil() }
    }

    /**
     * 根据tabid获取对应的fragment
     */    fun getFragment(tabId: Int): BaseFragment? {
        when (tabId) {
            R.id.menu_home -> return homeFragment
            R.id.home_find -> return messageFragment
            R.id.home_me -> return mineFragment
        }
        return null
    }
}